package com.example.mall.common.ddd;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;

import java.io.Serializable;
import java.util.Optional;

/**
 * @author Mickey
 * @since 2021/1/12
 */
public interface BaseRepository<T,ID extends Serializable> extends BaseMapper<T> {

    default Optional<T> byId(ID id) {
        return Optional.ofNullable(selectById(id));
    }

    default T save(T t) {
        insert(t);
        return t;
    }

    default T edit(T t) {
        updateById(t);
        return t;
    }
}
